#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int get(char c) {
  return c-'0';
}

int main () {
  int i,j ,k;
  vector<pair<int,string> > vec;
  int N, M; cin >> N >> M;
  string line;
  int meses[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  getline(cin, line);
  while (getline(cin, line)) {
    if (line == "") break;
    int seconds = 0;
    // 0-2012-(5)03-(8)16 (11)16:(14)15:(17)25
    seconds += get(line[17])*10+get(line[18]);
    seconds += (get(line[14])*10+get(line[15]))*60;
    seconds += (get(line[11])*10+get(line[12]))*3600;
    // days...
    seconds += (get(line[8])*10+get(line[9]))*3600*24;
    int month = get(line[5])*10+get(line[6]);
    for (i = 0; i+1 < month; ++i)
      seconds += meses[i] * 3600 * 24;
    vec.push_back(make_pair(seconds, line.substr(0, 19)));
  }
  sort(vec.begin(), vec.end());
  for (i = M-1; i < vec.size(); ++i)
    if (vec[i].first-vec[i-(M-1)].first < N) {
      cout << vec[i].second << endl;
      return 0;
    }
  cout << -1 << endl;
  return 0;
}
